package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = GameProtocol.S_HUA_SHI_GANG_GET_ELITE_REWARD_FROM_CROSS, desc = "领取精英怪奖励跨服返回")
public class GetEliteRewardFromCrossCmd extends AbstractCommand {

    private int ret;

    private String reward = "";

    private long allScore;

    private List<String> rewards = new ArrayList<>();

    private boolean oneKey;

    private List<Integer> y = new ArrayList<>();

    private List<Integer> rank = new ArrayList<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HuaShiGangProto.GetEliteRewardFromCross req = HuaShiGangProto.GetEliteRewardFromCross.parseFrom(packet.getBytes());
        ret = req.getRet();
        reward = req.getReward();
        allScore = req.getAllScore();
        rewards = req.getRewardsList();
        oneKey = req.hasOneKey() && req.getOneKey();
        y = req.getYList();
        rank = req.getRankList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CurrencyModule module = player.getModule(CurrencyModule.class);
        if (oneKey) {
            for (String s : rewards) {
                module.addCurrency(s, eLogMoneyType.HuaShiGang, eLogMoneyType.HuaShiGangEliteRankReward);
            }
        } else {
            module.addCurrency(reward, eLogMoneyType.HuaShiGang, eLogMoneyType.HuaShiGangEliteRankReward);
        }

        player.notifyListener(eGamePlayerEventType.HuaShiGangScoreRank.getValue(), allScore);

        HuaShiGangProto.GetEliteRewardRespMsg.Builder builder = HuaShiGangProto.GetEliteRewardRespMsg.newBuilder();
        builder.setRet(ret);
        builder.setReward(reward);
        if (oneKey) {
            builder.setOneKey(true);
            builder.addAllRewards(rewards);
            builder.addAllY(y);
            builder.addAllRank(rank);
        }
        player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_GET_ELITE_REWARD, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
